[root@node1 ~]# rpm -qi mysql-community-server Name : mysql-community-server Version : 5.7.34 Release : 1.el7 Architecture: x86_64 Install Date: Thu 27 May 2021 02:23:15 PM CST Group : Applications/Databases Size : 797908158 License : Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field. Signature : DSA/SHA1, Sat 27 Mar 2021 12:49:59 AM CST, Key ID 8c718d3b5072e1f5 Source RPM : mysql-community-5.7.34-1.el7.src.rpm Build Date : Fri 26 Mar 2021 03:24:41 PM CST Build Host : pb2-el7-07.appad3iad.mysql2iad.oraclevcn.com Relocations : (not relocatable) Packager : MySQL Release Engineering <mysql-build@oss.oracle.com> Vendor : Oracle and/or its affiliates URL : http://www.mysql.com/ Summary : A very fast and reliable SQL database server Description : The MySQL(TM) software delivers a very fast, multi-threaded, multi-user, and robust SQL (Structured Query Language) database server. MySQL Server is intended for mission-critical, heavy-load production systems as well as for embedding into mass-deployed software. MySQL is a trademark of Oracle and/or its affiliates
The MySQL software has Dual Licensing, which means you can use the MySQL software free of charge under the GNU General Public License (http://www.gnu.org/licenses/). You can also purchase commercial MySQL licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of the GPL. See the chapter "Licensing and Support" in the manual for further info.
The MySQL web site (http://www.mysql.com/) provides the latest news and information about the MySQL software. Also please see the documentation and the manual for more information.
This package includes the MySQL server binary as well as related utilities to run and administer a MySQL server.
出现以上信息说明安装成功
检查 mysql 源是否安装成功
1
yum repolist enabled | grep "mysql.*-community.*"
出现以下信息说明安装成功:
1 2 3
mysql-connectors-community MySQL Connectors Community 141 mysql-tools-community MySQL Tools Community 105 mysql57-community MySQL 5.7 Community Server
如果遇到版本不对,现象是客户端版本比较低,则需要执行更新操作:
1
dnf update mysql
启动MySQL
1
systemctl start mysqld
查看启动状态
1
systemctl status mysqld
出现以下信息,则启动成功
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[root@node1 ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) (thawing) since Thu 2021-05-27 14:35:11 CST; 4min 6s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 13463 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 13445 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 13466 (mysqld) Tasks: 29 (limit: 4752) Memory: 218.1M CGroup: /system.slice/mysqld.service └─13466 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
May 27 14:35:10 node1 systemd[1]: mysqld.service: Succeeded. May 27 14:35:10 node1 systemd[1]: Stopped MySQL Server. May 27 14:35:10 node1 systemd[1]: Starting MySQL Server... May 27 14:35:11 node1 systemd[1]: Started MySQL Server.
设置开机启动
1
systemctl enable mysqld
刷新所有修改过的配置文件
1
systemctl daemon-reload
获取安装mysql后生成的临时密码,用于登录
1
grep 'temporary password' /var/log/mysqld.log
# 如果出现如下列信息,密码为: Ldse65Csow#g
1
2021-05-27T06:25:51.106817Z 1 [Note] A temporary password is generated for root@localhost: Ldse65Csow#g
登录MySQL
1
mysql -uroot -p Ldse65Csow#g
# 再输入上面查找得到的临时密码即可进入mysql
修改登录密码
1 2 3
set global validate_password_policy=0; set global validate_password_length=1; ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
添加远程登录用户(即本机访问服务器上的MySQL)
1 2 3 4 5
mysql> GRANT ALL PRIVILEGES ON *.* TO 'zhangsan(用户名)'@'%' IDENTIFIED BY 'Zhangsan2018!(密码)' WITH GRANT OPTION; # 或者直接将root权限修改为可以通过远程访问(但不推荐) mysql> use mysql; mysql> UPDATE user SET Host='%' WHERE User='root'; mysql> flush privileges;
设置默认编码为utf-8(mysql安装后默认不支持中文)
1 2 3 4 5 6 7 8
vim /etc/my.cnf # 进入文件后添加下面的配置即可 [mysqld] character-set-server=utf8 [client] default-character-set=utf8 [mysql] default-character-set=utf8
重启MySQL服务并进入MySQL
1 2 3
shell> systemctl restart mysqld shell> mysql -uroot -p mysql> show variables like 'character%';